package com.itheima.demo1exception;

public class ExceptionDemo2 {

    public static void main(String[] args) {
        System.out.println("main开始");
        try {
            int t = div(10, 0);
            System.out.println("除法运算的结果是：" + t);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("程序出现异常");
        }
        System.out.println("main结束");
    }

    public static int div(int a, int b) throws Exception{
        if(b == 0){
            // 抛出异常，作为方法的特殊返回值
            throw new Exception("除数不能为0");
        }
        return a / b;
    }
}
